package com.zhijian.warehouse.manage.controller;

import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import com.zhijian.warehouse.manage.entity.po.OfficeGroup;
import com.zhijian.warehouse.manage.entity.vo.request.OfficeGroupSearchVo;
import com.zhijian.warehouse.manage.entity.vo.response.OfficeGroupVo;
import com.zhijian.warehouse.manage.service.OfficeGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 科室组织 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2022-01-01 15:41:01
 */
@Slf4j
@Controller
@Api(tags = "部门组织")
public class OfficeGroupController {

    @Autowired
    private OfficeGroupService service;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/office/group")
    @ApiOperation("新增")
    public boolean insert(@RequestBody OfficeGroup param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.insert(param) != null;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/office/group/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/office/group/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody OfficeGroup param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/office/group/{id}")
    @ApiOperation("根据id查询")
    public OfficeGroupVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/office/group/page")
    @ApiOperation("分页查询")
    public Page<OfficeGroupVo> selectByCondition(@RequestBody(required = false) OfficeGroupSearchVo param) {
        if (param == null)
            param = OfficeGroupSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 树状数据
     *
     * @return
     */
    @Response
    @GetMapping("/office/group/tree")
    @ApiOperation("树状数据")
    public List<OfficeGroupVo> officeGroupVoTreeList() {
        return service.renderTreeList();
    }

}